export function formatTime(time, tpl =
    "{year}{month}{day}{hour}{minute}{second}") {

    function _formatTime(date) {
        const d = date
        var year = d.getFullYear();
        var day = d.getDate();
        if (day < 10) {
            day = '0' + day;
        }
        var month = d.getMonth() + 1;
        if (month < 10) {
            month = '0' + month;
        }
        var hour = d.getHours();
        if (hour < 10) {
            hour = '0' + hour;
        }
        var minute = d.getMinutes();
        if (minute < 10) {
            minute = '0' + minute;
        }
        var second = d.getSeconds();
        if (second < 10) {
            second = '0' + second;
        }
        var millisecond = d.getMilliseconds();
        if (millisecond < 10) {
            millisecond = '00' + millisecond;
        } else if (millisecond < 100) {
            millisecond = '0' + millisecond;
        }
        return {
            year,
            month,
            day,
            hour,
            minute,
            second,
            millisecond
        };
    }
    let tmpDate;
    if (time) {
        tmpDate = new Date(time);
    } else {
        tmpDate = new Date();
    }
    let between = _formatTime(tmpDate)
    return tpl.replace(/{(\w*)}/g, function (m, key) {
        return between.hasOwnProperty(key) ? between[key] : "";
    });
}
